//
//  ST_GiftNumbersController.swift
//  btvideo
//
//  Created by Jason on 2021/7/19.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit

class ST_GiftNumbersController: UICollectionViewController {
    
    static func createController()->ST_GiftNumbersController{
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize(width: 110, height: 17)
        layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 0)
        return ST_GiftNumbersController(collectionViewLayout: layout)
    }
    
    var callBack:((ST_GiftNumberStruct?)->())?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        collectionView.backgroundColor = UIColor.init(hex: 0x202223)
        collectionView!.register(cellWithClass: ST_GiftNumbersCell.self)
        
        view.cornerRadius = 5
        view.borderColor = #colorLiteral(red: 1, green: 0.7970786095, blue: 0, alpha: 1)
        view.borderWidth = 1
        
    }

    // MARK: UICollectionViewDataSource


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        SC.numberOptions.count
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withClass: ST_GiftNumbersCell.self, for: indexPath)
        
        if let item_model = SC.numberOptions[safe: indexPath.item]{
            cell.bind(model: item_model)
        }
        
        return cell
    }

    // MARK: UICollectionViewDelegate
    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        callBack?(SC.numberOptions[safe: indexPath.item])
        
    }

}



//MARK: - Cell

class ST_GiftNumbersCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.centerY.equalToSuperview()
            make.width.equalTo(35)
        }
        contentView.addSubview(content_label)
        content_label.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(titleLabel.snp.right).offset(13)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var titleLabel:UILabel = {
       let control = UILabel()
        control.textColor = #colorLiteral(red: 0.9960784314, green: 0.7607843137, blue: 0.02745098039, alpha: 1)
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel()
         control.textColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
         control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.medium)
        return control
    }()
    
    func bind(model:ST_GiftNumberStruct) {
        
        titleLabel.text = model.number.string
        content_label.text = model.text
        
    }
}
